<template>
  <div class="app-container">
    <div class="content-box">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item title="操作提示" name="1">
          <ul>
            <li>设置—个主账户，结算时会优先打款至主账户</li>
            <li>收款账户最多不超过五个</li>
          </ul>
        </el-collapse-item>
      </el-collapse>
      <el-button type="primary" @click="add_open">新增账号</el-button>
      <el-table
        v-loading="loading"
        :data="list"
        row-key="id"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="sub_branch" label="开户行" align="center">
          <template slot-scope="scope">
            <div v-for="(item, index) in bank_list" :key="index">
              <div v-if="scope.row.bank_id == index">{{ item }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sub_branch" label="支行" align="center" />
        <el-table-column prop="account_name" label="账户名" align="center" />
        <el-table-column prop="card_number" label="账号" align="center" />
        <el-table-column prop="is_main" label="是否主账号" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.is_main == 1 ? "是" : "否" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding">
          <template slot-scope="scope">
            <el-button
              type="text"
              icon="el-icon-info"
              size="mini"
              @click="edit_open(scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="delet_bank(scope.row.account_id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination
        v-show="totalSize > 0"
        :total="totalSize"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      /> -->
      <!--地址 -->
      <el-dialog
        :title="is_add ? '新增' : '编辑'"
        :visible.sync="open"
        width="600px"
        append-to-body
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="开户行" prop="bank_id">
                <el-select v-model="form.bank_id" placeholder="请选择">
                  <el-option
                    v-for="(item, index) in bank_list"
                    :key="index"
                    :label="item"
                    :value="index"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="支行" prop="sub_branch">
                <el-input v-model="form.sub_branch" placeholder="请输入支行" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="账户名" prop="account_name">
                <el-input
                  v-model="form.account_name"
                  placeholder="请输入账户号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="账号" prop="card_number">
                <el-input v-model="form.card_number" placeholder="请输入账号" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="账号" prop="is_main">
                <el-radio-group v-model="form.is_main">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="is_add ? add_bank() : edit_bank()"
            >确 定</el-button
          >
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import pagination from "@/components/Pagination";
import {
  getlist,
  banklist,
  addbank,
  editbank,
  deletbank,
} from "@/api/collectionAccount";
export default {
  // components: {
  //   pagination,
  // },

  data() {
    return {
      options: [],
      queryParams: {},
      form: {},
      list: [],
      // 遮罩层
      loading: false,
      open: false,
      totalSize: 0,
      rules: {
        "form.bank_id": [{ required: true, message: "开户行不能为空" }],
        "form.bank_id": [{ required: true, message: "支行不能为空" }],
        "form.bank_id": [{ required: true, message: "账户号不能为空" }],
        "form.bank_id": [{ required: true, message: "账号不能为空" }],
      },
      activeName: "1",
      bank_list: [],
      is_add: true,
    };
  },
  created() {
    this.getLists();
    this.banklist();
  },
  methods: {
    add_open() {
      this.open = true;
      this.form = {};
      this.is_add = true;
    },
    edit_open(data) {
      this.open = true;
      this.form = {...data};
      this.is_add = false;
    },
    edit_bank() {
      let info = this.form;
      editbank(info).then((res) => {
        this.open = false;
        this.form = {};
        this.getLists();
      });
    },
    delet_bank(id) {
      deletbank({ account_id: id }).then((res) => {
        this.getLists();
      });
    },
    add_bank() {
      let info = this.form;
      addbank(info).then((res) => {
        this.open = false;
        this.getLists();
      });
    },
    banklist() {
      banklist().then((res) => {
        this.bank_list = res.data;
        console.log(res.data);
      });
    },
    getLists() {
      let info = {};
      console.log(1234);
      getlist().then((res) => {
        console.log(res);
        this.list = res.data.list;
        this.totalSize = res.data.total_page;
      });
    },
    cancel() {
      this.open = false;
      this.form = {};
    },
    submitForm() {},
    handleSelectionChange() {},
    getList() {},
  },
};
</script>

<style>
</style>
